package com.example.warehouse.contrallor;

import com.example.warehouse.entity.OutStore;
import com.example.warehouse.entity.Result;
import com.example.warehouse.entity.Store;
import com.example.warehouse.page.Page1;
import com.example.warehouse.service.OutstoreService;
import com.example.warehouse.service.StoreService;
import com.example.warehouse.utils.CurrentUser;
import com.example.warehouse.utils.TokenUtils;
import com.example.warehouse.utils.WarehouseConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/outstore")
public class contrallorOutstore{

    @Autowired
    private OutstoreService outstoreService;
    @Autowired
    private TokenUtils tokenUtils;
    @Autowired
    private StoreService storeService;
    @PostMapping("/outstore-add")
    public Result outstoreAdd(@RequestBody OutStore outStore,@RequestHeader(WarehouseConstants.HEADER_TOKEN_NAME) String token){
        CurrentUser currentUser = tokenUtils.getCurrentUser(token);
        outStore.setCreateTime(new Date());
        outStore.setCreateBy(currentUser.getUserId());
        outstoreService.outstoreAdd(outStore);
        return Result.ok("出库成功");
    }


    @RequestMapping("/store-list")
    public Result getAllStore(){
        List<Store> allStore = storeService.findAllStore();
        return Result.ok(allStore);
    }

    @RequestMapping("/outstore-page-list")
    public Result QueryPageOutStore(OutStore outStore, Page1 page1){
        page1=outstoreService.QueryPage(outStore,page1);
        return Result.ok(page1);
    }

    @PutMapping("/outstore-confirm")
    public Result ConfirmOutStore(@RequestBody OutStore outStore){
        outstoreService.OutStoreConfirm(outStore);
        return Result.ok("商品出库成功");
    }


}
